<?php
/**
 * Author: wl
 * Email: 446399160@qq.com
 * DateTime: 2017/04/22 11:33
 */

namespace app\modules\v1\models;
use yii\db\ActiveRecord;
use Yii;
use app\modules\v1\models\Weixinupload;

class Merchant extends ActiveRecord{

    public static function tableName()
    {
        return '{{merchant}}';
    }

    public function init()
    {
        parent::init();
    }
    
    public function WeixinRenzhengFail($name,$openid,$message='重复提交'){
    	//推送微信模板消息
    	$first 		 = '很遗憾'.$name.'，认证信息未通过\n';
    	$template_id = Yii::$app->params['template_id_rz_fail'];
    	$touser 	 = $openid;
    	$adgfa 		 = date("Y-m-d H:i:s",time()+8*3600);
    	$data = array(
    			'first'		=>array('value'=>urlencode("$first"),'color'=>"#743A3A"),
    			'keyword1'	=>array('value'=>$adgfa),
    			'keyword2'	=>array('value'=>urlencode("认证未通过")),
    			'keyword3'	=>array('value'=>urlencode("$message")),
    			'remark'	=>array('value'=>urlencode('很遗憾，您的收款认证信息未通过审核，请联系管理员！')),
    	);
    	$url 	  = '';
    	$weixinup = new Weixinupload();
    	$weixinup->doSend($touser, $template_id, $url, $data);
    }
    
    public function WeixinRenzhengOk($name,$openid,$message='重复提交'){
    	$first 		 = '尊敬的'.$name.'，恭喜您成为收款商家\n';
    	$template_id = Yii::$app->params['template_id_rz'];
    	$touser 	 = $openid;
    	$data = array(
    			'first'		=>array('value'=>urlencode("$first"),'color'=>"#743A3A"),
    			'keyword1'	=>array('value'=>urlencode("商家认证")),
    			'keyword2'	=>array('value'=>urlencode("认证成功")),
    			'keyword3'	=>array('value'=>date("Y-m-d H:i:s",time()+8*3600)),
    			'remark'	=>array('value'=>urlencode('您的收款认证信息已通过审核，可以使用收款功能啦')),
    			);
    	$url 	  = '';
    	$weixinup = new Weixinupload();
    	$weixinup->doSend($touser, $template_id, $url, $data);
    }
    
    public function WeixinOrderOk($openid,$money,$paytype,$date_time,$order_id){
    	$template_id 	= Yii::$app->params['template_id'];
    	$money 			= Number_format(floor($money*100)/100,2);
    	$data = array(
    			'first'		=>array('value'=>urlencode("您好,您有一笔订单收款成功"),'color'=>"#743A3A"),
    			'keyword1'	=>array('value'=>$money),
    			'keyword2'	=>array('value'=>urlencode("$paytype")),
    			'keyword3'	=>array('value'=>$date_time),
    			'keyword4'	=>array('value'=>$order_id),
    			'remark'	=>array('value'=>urlencode('详情请前往收款记录查看.')),
    	);
    	$url 	  = '';
    	$weixinup = new Weixinupload();
    	$weixinup->doSend($openid, $template_id, $url, $data);
    }
    
}